//
//  ViewApi.m
//  AppMua5
//
//  Created by duong nguyen on 9/13/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ViewApi.h"

@implementation ViewApi

#pragma NavigationController

// Set image for navigationbar
-(void) getCustomNavigationBar:(UINavigationBar *)bar{
    UIImage *img=[[UIImage alloc]init];
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone){
        img=[UIImage imageNamed:@"header_bar_iphone.png"];
    }else{
        img=[UIImage imageNamed:@"header_bar_ipad.png"];
    }
    float version=[[[UIDevice currentDevice]systemVersion]floatValue];
    if (version>=5.0) {
        [bar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
    }else {
        [bar insertSubview:[[UIImageView alloc]initWithImage:img] atIndex:1];
    }
    [img release];
}

// Moi khi vao ham viewDidLoad can set lai frame cho navigationBar
//
-(void) getCustomNavigationBarFrame:(UINavigationBar *)bar{
    if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
        [bar setFrame:CGRectMake(0, 20, 320, 39)];
    }else {
        // Don't need to set TabBar Frame because he is greater than default
        //[bar setFrame:CGRectMake(0, 20, 3, <#CGFloat height#>)
    }
}

#pragma Custom TabBar
// Thay doi image bacground cho footer
-(void) getCustomTabBarController:(UITabBar *)tabBar{
    if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
        [tabBar setBackgroundImage:[UIImage imageNamed:@"footer_iphone.png"]];
        [tabBar setFrame:CGRectMake(0, 436, 320, 44)];
    }else {
        [tabBar setBackgroundImage:[UIImage imageNamed:@"footer_ipad.png"]];
    }
    
}

// Loai bo khoang trang xuat hien giua view con va thanh TabBar
-(void) getCustomTabBarFrame:(UITabBarController *)tabBarController{
    if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
        [[tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 436)];
    }else {
        // Doi voi ipad vi kich thuot tabBar lon hon lich thuot mac d
    }
}

#pragma custom thanh header below.

// Set up header below.
-(void) getHeaderBelowView:(UIView *)view{
    if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
        [view setFrame:CGRectMake(0, -5 , 320, 30)];
        [view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"header_below_iphone.png"]]];
    }else {
        [view setFrame:CGRectMake(0, 50, 768, 70)];
         [view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"header_below_ipad.png"]]];
    }
}

#pragma custom table view
// Set up table view
-(void) getCustomTableView:(UITableView *)tableView{
    if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) {
        [tableView setFrame:CGRectMake(0, -5, 320, 379)];
        [tableView setRowHeight:350.0];
    }else {
        [tableView setFrame:CGRectMake(0, 50, 768, 1024)];
        [tableView setRowHeight:740.0];
    }
}

@end
